<template>
  <el-dialog
    :visible.sync="param.visible"
    title="添加字典"
    center
    :close-on-click-modal="false"
  >
    <Form1
      ref="addForm"
      :rules="rules"
      :form="addForm"
      :items="items"
      :save="addSave"
    >
    </Form1>
  </el-dialog>
</template>
<script>
import Form1 from "@/components/Form1.vue";
export default {
  name: "Add",
  components: { Form1 },
  props: {
    param: {
      type: Object,
      default: () => {},
    },
    typeId: { type: Number, default: () => {} },
  },
  data() {
    return {
      addForm: {
        //插入表单
        dict_key: "",
        dict_val: "",
        sort: 10,
        status: 0,
        type_id: this.typeId,
      },
      //验证规则
      rules: {
        dict_key: [
          { required: true, message: "字典键不能为空" },
          // { validator: validPassword, trigger: "blur" },
        ],
        dict_val: [{ required: true, message: "字典值不能为空" }],
        sort: [{ required: true, message: "排列的数量不能为空" }],
        status: [{ required: true, message: "状态不能为空" }],
      },
      items: [
        {
          type: "text",
          label: "字典的名称",
          prop: "dict_key",
          name: "dict_key",
          placeholder: "请输入字典名称",
        },
        {
          type: "text",
          label: "字典的值",
          prop: "dict_val",
          name: "dict_val",
          placeholder: "请输入字典名",
        },
        {
          type: "text",
          label: "序号：",
          prop: "sort",
          name: "sort",
          placeholder: "请输入序号",
        },

        {
          type: "select",
          label: "状态：",
          prop: "status",
          name: "status",
          placeholder: "请选择状态",
          options: [
            {
              value: 0,
              label: "正常",
            },
            {
              value: 1,
              label: "删除",
            },
          ],
        },
      ],
    };
  },

  methods: {
    //   保存
    addSave() {
      let flag = this.$refs["addForm"].validateForm();
      if (flag) {
        //   保存
        this.postRequest("/dict/", this.addForm).then((res) => {
          if (res) {
            this.$message.success(res.message);
            this.param.close(); //关闭
            this.param.callback(); //重新查询
          }
        });
      }
    },
  },
};
</script>
<style></style>
